package com.ruoyi.system.pay.mapper;

import com.ruoyi.system.pay.domain.po.PayOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 支付订单表 Mapper
 */
@Mapper
public interface PayOrderMapper {

    /**
     * 通过订单编号查询订单
     */
    //@Select("SELECT * FROM pay_order WHERE order_number = #{orderNumber}")
    PayOrder findByOrderNumber(@Param("orderNumber") String orderNumber);

    /**
     * 通过用户 ID 查询订单列表
     */
    //@Select("SELECT * FROM pay_order WHERE user_id = #{userId}")
    List<PayOrder> findByUserId(@Param("userId") Long userId);

    /**
     * 新增支付订单
     */
    //@Insert("INSERT INTO pay_order (user_id, order_number, amount, pay_method, status, created_at) " +
    //        "VALUES (#{userId}, #{orderNumber}, #{amount}, #{payMethod}, #{status}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertOrder(PayOrder order);

    /**
     * 更新订单状态
     */
    //@Update("UPDATE pay_order SET status = #{status}, payment_time = NOW(), updated_at = NOW() WHERE order_number = #{orderNumber}")
    int updateOrderStatus(@Param("orderNumber") String orderNumber, @Param("status") String status);

    /**
     * 更新订单状态和交易流水号
     */
    int updateOrder(@Param("order") PayOrder order);

}
